#{extends 'main.html' /}
#{set title:'fbregister' /}
<div id="content">
<br>
You are registered Bingo with using your Facebook account. <br>
Please enter your site password<br><br>

<form action="@{Users.save()}" method="POST" enctype="multipart/form-data" style="width:630px;">
	<input type="hidden" name="user.id" value="${user.id}" />
	<input type="hidden" name="user.fullname" value="${user.fullname}" class="user_fullname" />
	<input type="hidden" name="user.email" value="${user.email}" class="user_email" />
	<input type="hidden" name="photoURL" value="" class="user_photo" />
 	<ul class="long_login">
	    <li>
	      	<label>Full Name</label>
	      	<span class="user_fullname"></span>
	    </li>
	    <li>
	      	<label>Email</label>
	      	<span class="user_email"></span>
	    </li>
	    <li>
	    	<label>Photo</label>
	      	<img src="" alt="User photo" class="user_photo" />
	    </li>
	    <li>
	      <label>Password</label>
	      <input type="password" name="user.password" value="${user.password}" />
	      <span class="error">#{error 'user.password' /}</span>
	    </li>
    </ul>
    <input type="submit" class="login_button" name="submit" value="Submit" />
</form>
  
You can login to site with using your e-mail address and this password.

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '314694018611615', // App ID
      //channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    FB.getLoginStatus(function(response) {
    	  if (response.status === 'connected') {
    	   
    		  
    	    var uid = response.authResponse.userID;
    	    var accessToken = response.authResponse.accessToken;
    	    
    	    
    	    FB.api('/me', function(response) 
    	    { 
    	    	//alert("Name: "+ response.name + "\nFirst name: "+ response.first_name + "\nID: "+response.id
    	    		//	+"\nEmail:"+response.email);  
    	    
    	    	var fb_img_link = "http://graph.facebook.com/"+response.id+"/picture";
    	    	
    	    	// name.
    	    	$("input.user_fullname").val(response.name);
    	    	$("span.user_fullname").text(response.name);
    	    	
    	    	// email.
    	    	$("input.user_email").val(response.email);
    	    	$("span.user_email").text(response.email);
    	    	
    	    	// photo.
    	    	$("input.user_photo").val(fb_img_link);
    	    	$("img.user_photo").attr("src", fb_img_link);
    		}); 
    	    
    	  } else if (response.status === 'not_authorized') {
    	    // the user is logged in to Facebook, 
    	    // but has not authenticated your app
    	  } else {
    	    // the user isn't logged in to Facebook.
    	  }
    	 });
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

</script>

</div>
